package com.weijian.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weijian.dal.model.NotificationMessage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 消息通知Mapper接口
 */
@Mapper
public interface NotificationMessageMapper extends BaseMapper<NotificationMessage> {
    
    /**
     * 获取用户消息列表（分页）
     */
    @Select("SELECT * FROM notification_message WHERE user_id = #{userId} AND is_deleted = 0 ORDER BY created_time DESC")
    IPage<NotificationMessage> getUserMessages(Page<NotificationMessage> page, @Param("userId") Long userId);
    
    /**
     * 获取用户未读消息数量
     */
    @Select("SELECT COUNT(*) FROM notification_message WHERE user_id = #{userId} AND is_read = 0 AND is_deleted = 0")
    int getUnreadCount(@Param("userId") Long userId);
    
    /**
     * 获取用户各类型未读消息数量
     */
    @Select("SELECT type, COUNT(*) as count FROM notification_message WHERE user_id = #{userId} AND is_read = 0 AND is_deleted = 0 GROUP BY type")
    java.util.List<java.util.Map<String, Object>> getUnreadCountByType(@Param("userId") Long userId);
}